import argparse
import time

from logger import log
from settings import settings

# import tracemalloc

if __name__ == '__main__':
    # tracemalloc.start()
    start_time = time.time()
    parser = argparse.ArgumentParser(description='manual to this script')
    parser.add_argument("--code", type=str, default="test")
    parser.add_argument("--host", type=str, default="platform.wechain360.com")
    parser.add_argument("--local", type=bool, default=False)
    args = parser.parse_args()
    log.info(f"code:{args.code},host:{args.host},local:{args.local}")
    # 初始化配置
    settings.init(args.code, args.host, args.local)
    # 打开vm上传
    import metric

    metric.init()

    if settings.type == 'temperature':
        from temperature import main

        main()
    elif settings.type == 'access_control':
        from mqtt import MQTTClient

        # 开启mqtt发送状态
        MQTTClient().start()
        from face_access import main

        main()
    elif settings.type == 'wc_bangdan':
        from wc_bangdan import main

        main()
    elif settings.type == 'modbus':
        from modbus import main

        main()
    elif settings.type == 'train_txt':
        from train_txt import main

        main()
    elif settings.type == 'wc_train_cpz':
        from wc_train_cpz import main

        main()
    elif settings.type == 'nginx_heartbeat':
        from nginx_heartbeat import main

        main()
    elif settings.type == 'zkr_tos_rabbitmq':
        from zkr_tos_rabbitmq import main

        main()
    elif settings.type == 'wr_train':
        from wr_train import main

        main()
    else:
        from mqtt import MQTTClient

        # 开启mqtt发送状态
        MQTTClient().start()
        from weight import Weight

        weight = Weight()
        weight.init()
    log.info("启动完成")

    while True:
        time.sleep(0.1)

        # 每分钟运行一次
        # if time.time() - start_time >= 60:
        #     snapshot = tracemalloc.take_snapshot()
        #     top_stats = snapshot.statistics('lineno')
        #     log.info("[ Top 10 ]")
        #     for stat in top_stats[:10]:
        #         log.info(stat)
        #     # 重置计时器
        #     start_time = time.time()
